#include "DerivationTree.h"
#include "Integer.h"

IntegerNode::IntegerNode() : NodeTree_CRTP<IntegerNode>() { }

IntegerNode::IntegerNode(char* number, unsigned int _length) : NodeTree_CRTP<IntegerNode>(), buffer(number), length(_length) { }

IntegerNode::IntegerNode(const IntegerNode& copy) : NodeTree_CRTP<IntegerNode>(copy) {
	length = copy.length;
	buffer = new char[length];
	for (unsigned int i = 0; i < length; ++i) buffer[i] = copy.buffer[i];
}

bool IntegerNode::execute(Pointer<LeonardVirtualMachine> LVM) {
	long long int int_number = 0;
	unsigned int i = 0;
	while (i < length) {
		int_number = (int_number*10) + (buffer[i] - '0');
		++i;
	}
	AutoPointer<TreeExpression::Expression> ris(new TreeExpression::Integer(int_number));//TODO considerare memoria
	LVM->push(ris);
	return true;
}
